/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package io.renren.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.sys.dao.SysDictDao;
import io.renren.modules.sys.entity.SysDictEntity;
import io.renren.modules.sys.service.SysDictService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Map;


/**
 * 系统字典
 *
 * @author Mark sunlightcs@gmail.com
 */
@Service("sysDictService")
public class SysDictServiceImpl extends ServiceImpl<SysDictDao, SysDictEntity> implements SysDictService {


	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		String dictCode = (String)params.get("dictCode");
		String dictName = (String)params.get("dictName");
		IPage<SysDictEntity> page = this.page(
			new Query<SysDictEntity>().getPage(params),
			new QueryWrapper<SysDictEntity>()
				.like(StringUtils.isNotBlank(dictCode),"dict_code", dictCode)
					.like(StringUtils.isNotBlank(dictName),"dict_name", dictName)
		);

		return new PageUtils(page);
	}

	@Override
	public SysDictEntity queryByDictNameOrCode(String dictNameOrCode) {
		return baseMapper.queryByDictNameOrCode(dictNameOrCode);
	}

	@Override
	@Transactional
	public void saveDict(SysDictEntity dict) {
		this.save(dict);
	}

	@Override
	@Transactional
	public void update(SysDictEntity dict) {
		this.updateById(dict);
	}

	@Override
	public void deleteBatch(Long[] id) {
		this.removeByIds(Arrays.asList(id));
	}

}